package com.jifeng.api.exception.handler;

import com.jifeng.api.constant.HttpStatusEnum;
import com.jifeng.api.exception.CustomException;
import com.jifeng.api.utils.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author JiFeng
 */
@RestControllerAdvice
public class GlobalExceptionHandler{

    /**
     * 处理自定义异常
     * @param e 异常
     * @return R
     */
    @ExceptionHandler(CustomException.class)
    public R handleCustomException(CustomException e){
        return R.error(e.getHttpStatusEnum());
    }

    /**
     * 处理未知异常
     * @param e 错误码枚举
     * @return R
     */
    @ExceptionHandler(Exception.class)
    public R handleException(Exception e) {
        return R.sysError();
    }
}
